package cn.cau.epidemicsurveysystem.control;

import cn.cau.epidemicsurveysystem.bean.KnowledgeBean;
import cn.cau.epidemicsurveysystem.service.KnowledgeService;
import cn.cau.epidemicsurveysystem.vo.TemplateVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @projectName: gp2023
 * @package: cn.cau.epidemicsurveysystem.control
 * @className: KnowledgeController
 * @author: zy
 * @description: TODO
 * @date: 2022/3/2 16:43
 * @version: 1.0
 */
@Controller
@RequestMapping("/knowledge")
public class KnowledgeController {
    @Autowired
    KnowledgeService knowledgeService;

    /**
     * @param :
      * @return ModelAndView
     * @author zy
     * @description 返回所有知识库
     * @date 2022/3/2 16:45
     */
    @RequestMapping("/all")
    public ModelAndView getAll(){
        ModelAndView modelAndView = new ModelAndView();
        List<KnowledgeBean> allKnowledge = knowledgeService.getAllKnowledge();
        modelAndView.addObject(allKnowledge);
        modelAndView.setViewName("/");   //需要跳转的视图
        return modelAndView;
    }

    /**
     * @param id: 待传入的知识库id
      * @return KnowledgeBean ：返回相应的知识库实体
     * @author zy
     * @description TODO
     * @date 2022/3/2 16:48
     */
    @RequestMapping(value="/{id}",method= RequestMethod.GET)
    public ModelAndView getTemplateByName(@PathVariable("id") int id){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject(knowledgeService.getKnowledgeById(id));
        modelAndView.setViewName("/");   //需要跳转的视图
        return modelAndView;
    }

}
